import date from './components/date.vue'
import tree from './components/tree.vue'
export default {
  components: {
    date,
    tree
  },
  data() {
    return {
      id: '',
      index: 0,
      isDate: false,
      maxDate: '',
      maxYear: '',
      pageLoading: false,
      startDate: '', //开始日期
      endDate: '', //结束日期
      selectedDate: '', //当天日期
      list: {},
      listArr: [],
      loadStatus: '',
      pageIndex: 1,
      isMore: false,
      arrList: [],
      listArrs: [
        {
          id: 0,
          address: '地址',
          station_Name: '洗车店',
          addMoney: 1,
          lossMoney: 1,
          theCardSales: 1,
          timeCardSales: 1,
          clockSales: 1,
          topupSales: 1,
          onlineTheCardSales: 1,
          onlineYesterday: 1,
          onlineEarnings: 1,
          andCustomerNumber: 1,
          yesterday: 1,
          earnings: 1,
          thisMonth: 1,
          dataList: [{
            id: 0,
            machine_Name: '名字0',
            machine_Code: '编码0',
            yesterday: 1,
            duringmonth: 1,
            earnings: 1,
            andCustomerNumber: 1,
            addCustomerNumber: 1,
            lossCustomerNumber: 1,
            theCardSales: 1,
            timeCardSales: 1,
            clockSales: 1,
            addMoney: 1,
            lossMoney: 1,
            theCardSales: 1,
            topupSales: 1,
            thisMonth: 1,
          },
          {
            id: 1,
            machine_Name: '名字1',
            machine_Code: '编码1',
            yesterday: 1,
            duringmonth: 1,
            earnings: 1,
            andCustomerNumber: 1,
            addCustomerNumber: 1,
            lossCustomerNumber: 1,
            theCardSales: 1,
            timeCardSales: 1,
            clockSales: 1,
            addMoney: 1,
            lossMoney: 1,
            topupSales: 1,
            thisMonth: 1,
          },
          {
            id: 2,
            machine_Name: '名字2',
            machine_Code: '编码2',
            yesterday: 1,
            duringmonth: 1,
            earnings: 1,
            andCustomerNumber: 1,
            addCustomerNumber: 1,
            lossCustomerNumber: 1,
            clockSales: 1,
            addMoney: 1,
            lossMoney: 1,
            theCardSales: 1,
            timeCardSales: 1,
            topupSales: 1,
            thisMonth: 1,
          }
          ]
        },
        {
          id: 1,
          address: '',
          station_Name: '洗车机',
          addMoney: 2,
          lossMoney: 2,
          theCardSales: 2,
          timeCardSales: 2,
          clockSales: 2,
          topupSales: 2,
          onlineTheCardSales: 2,
          onlineYesterday: 2,
          onlineEarnings: 2,
          andCustomerNumber: 2,
          yesterday: 2,
          earnings: 2,
          thisMonth: 2,
          dataList: [{
            id: 0,
            machine_Name: '名字1-1',
            machine_Code: '编码1-1',
            yesterday: 1,
            duringmonth: 1,
            earnings: 1,
            andCustomerNumber: 1,
            addCustomerNumber: 1,
            lossCustomerNumber: 1,
            timeCardSales: 1,
            clockSales: 1,
            addMoney: 1,
            lossMoney: 1,
            theCardSales: 1,
            topupSales: 1,
            thisMonth: 2,
          },
          {
					  id: 1,
					  machine_Name: '名字1-2',
					  machine_Code: '编码1-2',
					  yesterday: 1,
					  duringmonth: 1,
					  earnings: 1,
					  andCustomerNumber: 1,
					  addCustomerNumber: 1,
					  lossCustomerNumber: 1,
					  theCardSales: 1,
					  timeCardSales: 1,
					  clockSales: 1,
            addMoney: 1,
            lossMoney: 1,
            topupSales: 1,
            thisMonth: 2,
          }]
        }
      ]
    }
  },
  onLoad(op){
    this.id = op.id
  },
  created() {
    this.selectedDate = this.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd')
    this.getMyBusinessReport()
  },
  onReady() {
    this.maxYear = this.selectedDate = this.$u.timeFormat(new Date().getTime(), 'yyyy')
    //当前年
    this.maxDate = this.selectedDate = this.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd')
    console.log(this.maxDate)
    this.pageLoading = true
  },
  filters: {
    million(value) { //过万处理
      let num = 0
      num = Number(value).toFixed(2)
      return num
    }
  },
  methods: {
    moreStatus(status) {
      this.loadStatus = status
    },
    async getMyBusinessReport() {
      this.loadStatus = 'loading'
      try {
        let data = {
          'pageIndex': this.pageIndex,
          'pageSize': 100,
          'startDateTime': this.startDate,
          'endDateTime': this.endDate,
          'station_id': this.id
        }
        const res = await this.$api.washCar.getMyBusinessReport(data)
        this.list = res.data
        this.listArr = res.data.data.list

      } catch (e) {
        //TODO handle the exception
      }
    },
    chooseDate(e) {
      console.log(e)
      this.list = []
      this.listArr = []
      this.pageIndex = 1
      this.startDate = e.startDate
      this.endDate = e.endDate
      this.getMyBusinessReport()
    }
  }
}
